<?php

class Data extends CI_Controller {

	public function __construct() {
		parent::__construct();
		$this->load->model('model_data');
		if (! $this->usersession->userLoggedIn()) {
			$aResponse = array("error" => TRUE, "description" => "Sesiunea a expirat", "type" => "nosession");
			die(json_encode($aResponse));
		}
		$this->aUser = $this->usersession->currentUser();
		copyPost($this->aPost);
	}


	function getJudet() {
		echo json_encode($this->model_data->getJudet($this->aPost));
	}

	function getOras() {
		echo json_encode($this->model_data->getOras($this->aPost));
	}

	function getDepartament() {
		echo json_encode($this->model_data->getDepartament($this->aPost));
	}

	function getFunctie() {
		echo json_encode($this->model_data->getFunctie($this->aPost));
	}

	function getFunctieSub() {
		echo json_encode($this->model_data->getFunctieSub($this->aPost));
	}

	function getDomeniu() {
		echo json_encode($this->model_data->getDomeniu($this->aPost));
	}

	function getDomeniuSub() {
		echo json_encode($this->model_data->getDomeniuSub($this->aPost));
	}


	function getClient() {
		echo json_encode($this->model_data->getClient($this->aPost));
	}
	function getCampanie() {
		echo json_encode($this->model_data->getCampanie($this->aPost));
	}


	/**
	 * functie de adaugare generala din meniu Operatii
	 */
	function addObject() {
		$sData = $this->aPost['data'];
		$sTabel = $this->aPost['table'];
		$parent = isset($this->aPost['data_parent']) ? $this->aPost['data_parent'] : NULL;

		$result = $this->model_data->addObject($sData, $sTabel, $parent);
		if ($result) {
			$aResponse = array("error" => FALSE, "description" => "Datele au fost salvate", "type" => "data");
		} else {
			$aResponse = array("error" => TRUE, "description" => "Exista duplicat", "type" => "data");
		}
		echo json_encode($aResponse);
	}

	function addFunctieSub() {
		$sData = $this->aPost['data'];
		$iFunctie =$this->aPost['functie_id'];

		$result = $this->model_data->addFunctieSub($sData, $iFunctie);
		if ($result) {
			$aResponse = array("error" => FALSE, "description" => "Datele au fost salvate", "type" => "data");
		} else {
			$aResponse = array("error" => TRUE, "description" => "Exista duplicat", "type" => "data");
		}
		echo json_encode($aResponse);
	}

	function addDomeniuSub() {
		$sData = $this->aPost['data'];
		$iDomeniu =$this->aPost['domeniu_id'];

		$result = $this->model_data->addDomeniuSub($sData, $iDomeniu);
		if ($result) {
			$aResponse = array("error" => FALSE, "description" => "Datele au fost salvate", "type" => "data");
		} else {
			$aResponse = array("error" => TRUE, "description" => "Exista duplicat", "type" => "data");
		}
		echo json_encode($aResponse);
	}

	function addCampanie() {
		$sData = $this->aPost['data'];
		$iClient =$this->aPost['client_id'];
		$iTip =$this->aPost['client_id'];

		$result = $this->model_data->addCampanie($sData, $iClient, $iTip);
		if ($result) {
			$aResponse = array("error" => FALSE, "description" => "Datele au fost salvate", "type" => "data");
		} else {
			$aResponse = array("error" => TRUE, "description" => "Exista duplicat", "type" => "data");
		}
		echo json_encode($aResponse);
	}


	/*
		function bringObject() {
			$result = $this->model_data->bringObject($this->aPost);
			$aResult = array(
				"error" => FALSE,
				rows    => $result
			);
			echo $aResult;
		}*/


	/*
	function bringCompany() {
		$result = $this->model_data->bringCompany($_POST);
		echo '{rows:'.json_encode($result).'}';
	}*/

	/**
	 * Functie care aduce domeniul - concatenat cu subdomeniul. In plus se aduce si domeniul simplu ( fara concatenare de subdomeniu ) pentru cazul in care se doreste doar completarea domeniului
	 */
	/*function bringSubdomain() {
		$result = $this->model_data->bringSubdomain($_POST);
		echo '{rows:'.json_encode($result).'}';
	}*/

}
